<template>
  <div class="app-container">
    <el-card v-show="showSearch" style="margin-bottom: 20px">
      <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams">
      <el-form-item label="业务标志" prop="businessKey">
        <el-input
          v-model="queryParams.businessKey"
          clearable
          placeholder="请输入业务标志"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点名称" prop="nodeName">
        <el-input
          v-model="queryParams.nodeName"
          clearable
          placeholder="请输入节点名称"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点值" prop="nodeValue">
        <el-input
          v-model="queryParams.nodeValue"
          clearable
          placeholder="请输入节点值"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input
          v-model="queryParams.sort"
          clearable
          placeholder="请输入排序"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <el-card>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button-group>
            <el-button
              icon="el-icon-plus"
              size="mini"
              type="success"
              @click="handleAdd"
            >新增
            </el-button>
          </el-button-group>
        </el-col>
        <el-col :span="1.5">
          <el-button-group>
            <el-button
              :disabled="single"
              icon="el-icon-edit"
              size="mini"
              type="primary"
              @click="handleUpdate"
            >修改
            </el-button>
            <el-button
              :disabled="single"
              icon="el-icon-delete"
              size="mini"
              type="primary"
              @click="handleDelete"
            >删除
            </el-button>
          </el-button-group>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="configureList" height="calc(100vh - 241px)"
                highlight-current-row @current-change="handleCurrentChange"
      >
        <el-table-column align="center" label="ID" prop="id" width="100px"/>
        <el-table-column align="left" label="业务标志" prop="businessKey"/>
        <el-table-column align="left" label="节点名称" prop="nodeName"/>
        <el-table-column align="left" label="节点值" prop="nodeValue"/>
        <el-table-column align="center" label="排序" prop="sort"/>
        <el-table-column align="left" label="备注" prop="remark" width="400"/>
        <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
          <template slot-scope="scope">
            <el-button
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
            >修改
            </el-button>
            <el-button
              icon="el-icon-delete"
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </el-card>
    <edit ref="editDialog" @refreshDataList="getList"></edit>
  </div>
</template>

<script>
import { listConfigure, delConfigure, exportConfigure } from '@/api/processSchedule/configure'
import Edit from './edit'

export default {
  name: 'Configure',
  components: { Edit },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      id: '',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 流程进度配置表格数据
      configureList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessKey: null,
        nodeName: null,
        nodeValue: null,
        sort: null
      }
    }

  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询流程进度配置列表 */
    getList() {
      this.loading = true
      listConfigure(this.queryParams).then(response => {
        this.configureList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    //选中数据
    handleCurrentChange(val) {
      if (val) {
        this.id = val.id
        if (this.id) {
          this.single = false
        }
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs['editDialog'].reset()
      this.$refs['editDialog'].open = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs['editDialog'].reset()
      this.$refs['editDialog'].open = true
      const id = row.id || this.id
      this.$refs['editDialog'].init(id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.id
      this.$confirm('是否确认删除流程进度配置编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delConfigure(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有流程进度配置数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportConfigure(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(function() {
      })
    }
  }
}
</script>
